<?php
/**
 * BActiveGoogleMapTestCase.php
 * 
 * @author Bradley Booms <Bradley.Booms@nsighttel.com>
 * @version Creation Date: Jun 7, 2007
 */

/**
 * BActiveGoogleMapTestCase.php class
 * 
 * 
 * 
 * Properties
 * -
 * 
 * @author Bradley Booms <Bradley.Booms@nsighttel.com>
 * @version Modified Date: Jun 7, 2007
 * 
 * Modifications:
 */
class BActiveGoogleMapTestCase extends SeleniumTestCase{
	function test(){
		// this test does not work in IE, but does in mozilla and opera, Not tested in Safari.
		$this->skipBrowsers(self::INTERNET_EXPLORER);
		
		$this->setTimeout(6000);
		$this->open("functional/index.php?page=BActiveGoogleMapTest");
		$this->assertTextPresent("BActiveGoogleMap Functional Test");

		/**
		 * Check for the proper controls
		 * GLargeMapControl		img src="http://www.google.com/intl/en_us/mapfiles/mapcontrols2.png"
		 * GScaleControl		img src="http://www.google.com/intl/en_us/mapfiles/mapcontrols2.png"
		 * GOverviewMapControl	id="Map_overview"
		 * GMapTypeControl		Text="Map", "Satellite", "Hybrid"
		 */
		$this->waitForElementPresent("//img[contains(@src, 'mapfiles/mapcontrols2.png')]");
		$this->verifyElementPresent("Map_overview");
		$this->assertTextPresent("Map");
		$this->assertTextPresent("Satellite");
		$this->assertTextPresent("Hybrid");
//		$this->verifyElementPresent("//img[@src='http://www.google.com/intl/en_us/mapfiles/scale.png']");

		/**
		 * Initial Conditions:
		 * Center 				44.535,-89.24
		 * Zoom Level			14
		 * img src attribute	&x=4130&y=5923&zoom=3
		 */
		$this->assertElementPresent("//img[contains(@src,'&x=4130') and contains(@src,'&y=5923') and contains(@src,'&z=14')]");
		/**
		 * Make sure that the shadow and marker icons are present.
		 * src = http://www.google.com/intl/en_us/mapfiles/shadow50.png
		 * src = http://www.google.com/intl/en_us/mapfiles/marker.png
		 */
		$this->waitForElementPresent("//img[contains(@src, 'mapfiles/shadow50.png')]");
		$this->assertElementPresent("//img[contains(@src, 'mapfiles/marker.png')]");
		$this->assertElementPresent("//img[contains(@src, 'marker-BLUE-DOT.png')]");
		$this->assertElementPresent("//img[contains(@src, 'mapfiles/ms/micons/green-dot.png')]");
		
		/**
		 * Make sure that the markers are in the right places.
		 * style contains "left: 381px; top: 304px;"
		 * style contains "left: 346px; top: 255px;"
		 * style contains "left: 311px; top: 206px;"
		 * style contains "left: 276px; top: 157px;"
		 * style contains "left: 241px; top: 92px;"
		 */
		$this->assertElementPresent("//img[contains(@style,'left: 381px;') and contains(@style,'top: 304px;')]");
		$this->assertElementPresent("//img[contains(@style,'left: 346px;') and contains(@style,'top: 255px;')]");
		$this->assertElementPresent("//img[contains(@style,'left: 311px;') and contains(@style,'top: 206px;')]");
		$this->assertElementPresent("//img[contains(@style,'left: 270px;') and contains(@style,'top: 159px;')]");
		$this->assertElementPresent("//img[contains(@style,'left: 241px;') and contains(@style,'top: 92px;')]");
		
		$this->click("info");
		$this->waitForText("label", "Opened info window for marker Test0.");
//		$this->waitForElementPresent("iwMap0");
//		$this->assertElementPresent("//area[contains(@coords, '11,61,8,62,6,63,4,65,2,69,2,73,3,75,4,77,7,80,9,84,10,87,11,91,11,95,13,95,13,91,14,87,15,85,16,82,18,79,20,77,22,73,22,69,20,65,18,63,17,62,15,61')]");
		
//		$this->type("innerControl", "This is a test of the emergency broadcasting network...");
		// commented, this doesn't seem to work properly in the automated test environment.
//		$this->click("innerButton");
//		$this->waitForText("label", "This is a test of the emergency broadcasting network...");
		
		$this->click("infoClose");
		$this->waitForText("label", "Closed info window.");
//		$this->waitForElementPresent("//area[contains(@coords, '0,0,0,0')]");
		
		$this->click("zoom");
		$this->waitForText("label", "Set zoom level to 16.");
		/**
		 * Conditions After zoom1 Click:
		 * Center 				44.535,-89.24
		 * Zoom Level			16
		 * img src attribute	&x=16522&y=23694&zoom=1
		 */
		$this->waitForElementPresent("//img[contains(@src,'&x=16522') and contains(@src,'&y=23694') and contains(@src,'&z=16')]");
		/**
		 * Make sure that the markers are in the right places.
		 * style contains "left: 171px; top: 10px;"
		 * style contains "left: 311px; top: 206px;"
		 * style contains "left: 450px; top: 402px;"
		 */
		$this->assertElementPresent("//img[contains(@style,'left: 165px;') and contains(@style,'top: 12px')]");
		$this->assertElementPresent("//img[contains(@style,'left: 311px;') and contains(@style,'top: 206px;')]");
		$this->assertElementPresent("//img[contains(@style,'left: 450px;') and contains(@style,'top: 402px')]");
		
		
		$this->click("recenter");
		$this->waitForText("label", "Set center to (44.33,-89.22).");
		/**
		 * Conditions After recenter1 Click:
		 * Center 				44.33,-89.22
		 * Zoom Level			16
		 * img src attribute	&x=16525&y=23746&zoom=1
		 */
		$this->waitForElementPresent("//img[contains(@src,'&x=16525') and contains(@src,'&y=23746') and contains(@src,'&z=16')]");
		/**
		 * Make sure that the markers are in the right places.
		 * style contains "left: 404px; top: 337px;"
		 * style contains "left: 357px; top: 271px;"
		 * style contains "left: 311px; top: 206px;"
		 * style contains "left: 264px; top: 141px;"
		 * style contains "left: 217px; top: 76px;"
		 */
		$this->waitForElementPresent("//img[contains(@style,'left: 404px;') and contains(@style,'top: 337px;')]");
		$this->assertElementPresent("//img[contains(@style,'left: 357px;') and contains(@style,'top: 271px;')]");
		$this->assertElementPresent("//img[contains(@style,'left: 311px;') and contains(@style,'top: 206px;')]");
		$this->assertElementPresent("//img[contains(@style,'left: 264px;') and contains(@style,'top: 141px;')]");
		$this->assertElementPresent("//img[contains(@style,'left: 217px;') and contains(@style,'top: 76px;')]");
		
		$this->click("controls");
		$this->waitForText("label", "Changed map controls.");
		/**
		 * Conditions After controls1 Click:
		 * GSmallMapControl		img src="http://www.google.com/intl/en_us/mapfiles/smc.png"
		 * GMapTypeControl		Text="Map", "Satellite", "Hybrid"
		 */
		$this->waitForElementPresent("//img[contains(@src, 'mapfiles/smc.png')]");
		$this->assertTextPresent("Map");
		$this->assertTextPresent("Satellite");
		$this->assertTextPresent("Hybrid");
		
		$this->verifyElementNotPresent("//img[contains(@src, 'mapfiles/lmc.png')]");
		$this->verifyElementNotPresent("Map_overview");
		$this->verifyElementNotPresent("//img[contains(@src, 'mapfiles/scale.png')]");
		
		
		$this->click("bounds");
		$this->waitForText("label", "Set bounds to (44.303, 44.362, -89.277, -89.166).");
		/**
		 * Conditions After changeBounds Click:
		 * img src attribute	&x=2065&y=2968&zoom=4
		 */
		$this->waitForElementPresent("//img[contains(@src,'&x=2065')and contains(@src,'&y=2968')and contains(@src,'&z=13')]");
		
	/**
	 * Click and move.
	 * Slenium isn't too great at this, at least not from what I've found.
	 *
		
		$this->clickAt("//img[contains(@src,'&x=2065')and contains(@src,'&y=2968')and contains(@src,'&zoom=4')]", "110,50");
//		$this->mouseDownAt("//img[contains(@src,'&x=2065')and contains(@src,'&y=2968')and contains(@src,'&zoom=4')]", "110,50");
//		$this->mouseUpAt("//img[contains(@src,'&x=2065')and contains(@src,'&y=2968')and contains(@src,'&zoom=4')]", "110,50");
		
		$this->waitForText("label", "Marker added at (44.3333034407, -89.234046936).");
		$this->waitForElementPresent("//img[contains(@style,'left: 236px;') and contains(@style,'top: 197px;')]");
		
		$this->dragAndDrop("//area[contains(@title, 'Test10')]", "+2200,-750");
		$this->waitForText("label", "Marker moved to (44.3345312988, -89.2323303223).");
	 */
	}
}
?>